package cn.school.controller.workmgr;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.workmgr.entity.HygieneDormitory;
import cn.school.workmgr.service.FenceService;
import cn.school.workmgr.vo.FenceConfigVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 地理围栏
 */
@RestController
@Api(tags = "FenceController => 地理围栏")
@RequestMapping("/fence")
public class FenceController {

    @Resource
    FenceService fenceService;

    @PostMapping("/list")
    public CommonResult<CommonPage<FenceConfigVO>> pageList(@RequestBody FenceConfigVO vo) {
        // 查询
        IPage<FenceConfigVO> pageList = fenceService.pageList(vo);
        return CommonResult.success(CommonPage.restPage(pageList));
    }

    @PostMapping("/addOrupdate")
    public CommonResult<Integer> addOrupdate(@RequestBody FenceConfigVO vo) {
        // 查询
        Integer num = fenceService.addOrUpdateFenceConfig(vo);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @PostMapping("/del")
    public CommonResult<Integer> deleteById(@RequestBody FenceConfigVO vo) {
        // 查询
        Integer num = fenceService.deleteFenceConfig(vo.getId());
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @GetMapping("/detail/{id}")
    public CommonResult<FenceConfigVO> fenceDetail(@PathVariable("id") Long id) {
        // 查询
        FenceConfigVO vo = fenceService.fenceDetail(id);
        return CommonResult.success(vo);
    }

}
